home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / menudemo / cdio.c next >
C/C++ Source or Header  |  1986-01-15  |  4KB  |  130 lines

  1.  
  2. /*********************************************************************/
  3. /* CDIO.C AmigaLink 1/25/86                                          */
  4. /*                     Copyright (c) 1985                            */
  5. /*                    Commodore-Amiga, Inc.                          */
  6. /*                    All rights reserved.                           */
  7. /*                                                                   */
  8. /*     No part of this program may be reproduced, transmitted,       */
  9. /*     transcribed, stored in retrieval system, or translated        */
  10. /*     into any language or computer language, in any form or        */
  11. /*     by any means, electronic, mechanical, magnetic, optical,      */
  12. /*     chemical, manual or otherwise, without the prior written      */
  13. /*     permission of:                                                */
  14. /*                     Commodore-Amiga, Inc.                         */
  15. /*                     983 University Ave #D                         */
  16. /*                     Los Gatos, CA. 95030                          */
  17. /*                                                                   */
  18. /*********************************************************************/
  19.  
  20. /*********************************************************************/
  21. /*                                                                   */
  22. /*  Program name:  cdio                                              */
  23. /*                                                                   */
  24. /*  Purpose:  To provide standard console device interface routines  */
  25. /*            such as Open, GetChar, PutChar, etc.                   */
  26. /*                                                                   */
  27. /*  Arguments:  (window)    - The window to associate the console    */
  28. /*                            device with. Used in CDOpen.           */
  29. /*              (character) - The char to output. Used in CDPutChar  */
  30. /*              (string)    - The string to output. Used in CDPutStr */
  31. /*                                                                   */
  32. /*********************************************************************/
  33.  
  34. #include "standard.h"
  35.  
  36. struct IOStdReq consoleIO = 0;
  37. struct IOStdReq consoleREADIO = 0;
  38. struct MsgPort consoleMsgPort = 0;
  39. UBYTE consoleReadChar = 0;
  40.  
  41. int CDOpen(window)
  42. struct Window *window;
  43. {
  44.      int error;
  45.           
  46. /* Open the console device */
  47.      consoleIO.io_Data = (char *) window;
  48.      consoleIO.io_Length = sizeof(*window);
  49.      if ((error = OpenDevice("console.device", 0, &consoleIO, 0)) != 0)
  50.      {
  51.           return(error);
  52.      }
  53.  
  54. /* Set up the message port in the I/O request */
  55.      consoleMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  56.      consoleMsgPort.mp_Flags = 0;
  57.      consoleMsgPort.mp_SigBit = AllocSignal(-1);
  58.      consoleMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  59.      AddPort(&consoleMsgPort);
  60.      consoleIO.io_Message.mn_ReplyPort = &consoleMsgPort;
  61.  
  62. /* Start reading */
  63.      consoleREADIO = consoleIO;
  64.      queue_read();
  65.  
  66.      return(0);
  67. }
  68.  
  69. CDClose()
  70. {
  71.      RemPort(&consoleMsgPort);
  72.      CloseDevice(&consoleIO);
  73. }
  74.  
  75. int CDMayGetChar()
  76. {
  77.      register temp;
  78.  
  79.      if ( GetMsg(&consoleMsgPort) == NULL ) return(-1);
  80.      temp = consoleReadChar;
  81.      queue_read();
  82.      return(temp);
  83. }
  84.  
  85. queue_read()
  86. {
  87.      consoleREADIO.io_Command = CMD_READ;
  88.      consoleREADIO.io_Data = &consoleReadChar;
  89.      consoleREADIO.io_Length = 1;
  90.      SendIO(&consoleREADIO);              /* Due to bug in DoIO */
  91. }
  92.  
  93. UBYTE CDGetChar()
  94. {
  95.      register temp;
  96.  
  97.      while (GetMsg(&consoleMsgPort) == NULL) ; /* during console IO */
  98.      temp = consoleReadChar;
  99.      queue_read();
  100.      return(temp);
  101. }
  102.  
  103. CDPutChar(character)
  104. char character;
  105. {
  106.      consoleIO.io_Command = CMD_WRITE;
  107.      consoleIO.io_Data = &character;
  108.      consoleIO.io_Length = 1;
  109.      DoIO(&consoleIO);
  110. }
  111.  
  112. CDPutStr(string)
  113. char *string;       /*  NULL terminated string to output  */
  114. {
  115.      consoleIO.io_Command = CMD_WRITE;
  116.      consoleIO.io_Data = string;
  117.      consoleIO.io_Length = -1;
  118.      DoIO(&consoleIO);
  119. }
  120.  
  121. CDPutStrL(string,length)
  122. char *string;       /*  output a string of length length */
  123. int length;
  124. {
  125.      consoleIO.io_Command = CMD_WRITE;
  126.      consoleIO.io_Data = string;
  127.      consoleIO.io_Length = length;
  128.      DoIO(&consoleIO);
  129. }
  130.